﻿using System;
using System.Data;
using System.Collections.Generic;
using XYW.Common;
using XYW.Model;
namespace XYW.BLL
{
	/// <summary>
	/// Activitys
	/// </summary>
	public partial class Activitys
	{
		private readonly XYW.DAL.Activitys dal=new XYW.DAL.Activitys();
		public Activitys()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			return dal.Exists(ID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(XYW.Model.Activitys model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XYW.Model.Activitys model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			return dal.Delete(ID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			return dal.DeleteList(IDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XYW.Model.Activitys GetModel(int ID)
		{
			
			return dal.GetModel(ID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public XYW.Model.Activitys GetModelByCache(int ID)
		{
			
			string CacheKey = "ActivitysModel-" + ID;
			object objModel = XYW.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(ID);
					if (objModel != null)
					{
						int ModelCache = XYW.Common.ConfigHelper.GetConfigInt("ModelCache");
						XYW.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (XYW.Model.Activitys)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<XYW.Model.Activitys> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<XYW.Model.Activitys> DataTableToList(DataTable dt)
		{
			List<XYW.Model.Activitys> modelList = new List<XYW.Model.Activitys>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				XYW.Model.Activitys model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new XYW.Model.Activitys();
					if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="")
					{
						model.ID=int.Parse(dt.Rows[n]["ID"].ToString());
					}
					if(dt.Rows[n]["actName"]!=null && dt.Rows[n]["actName"].ToString()!="")
					{
					model.actName=dt.Rows[n]["actName"].ToString();
					}
					if(dt.Rows[n]["actCont"]!=null && dt.Rows[n]["actCont"].ToString()!="")
					{
					model.actCont=dt.Rows[n]["actCont"].ToString();
					}
					if(dt.Rows[n]["actUserId"]!=null && dt.Rows[n]["actUserId"].ToString()!="")
					{
						model.actUserId=int.Parse(dt.Rows[n]["actUserId"].ToString());
					}
					if(dt.Rows[n]["actUserName"]!=null && dt.Rows[n]["actUserName"].ToString()!="")
					{
					model.actUserName=dt.Rows[n]["actUserName"].ToString();
					}
					if(dt.Rows[n]["actTime"]!=null && dt.Rows[n]["actTime"].ToString()!="")
					{
						model.actTime=DateTime.Parse(dt.Rows[n]["actTime"].ToString());
					}
					if(dt.Rows[n]["actAddress"]!=null && dt.Rows[n]["actAddress"].ToString()!="")
					{
					model.actAddress=dt.Rows[n]["actAddress"].ToString();
					}
					if(dt.Rows[n]["actPersonLimit"]!=null && dt.Rows[n]["actPersonLimit"].ToString()!="")
					{
						model.actPersonLimit=int.Parse(dt.Rows[n]["actPersonLimit"].ToString());
					}
					if(dt.Rows[n]["actStatus"]!=null && dt.Rows[n]["actStatus"].ToString()!="")
					{
					model.actStatus=dt.Rows[n]["actStatus"].ToString();
					}
					if(dt.Rows[n]["actType"]!=null && dt.Rows[n]["actType"].ToString()!="")
					{
					model.actType=dt.Rows[n]["actType"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

